//-------------------------------------------------------------------
//	Copyright (c) 2010-2014  Zhirnov Andrey
//	This file is part of the "UX Standard Lib" project.
//	See copyright notice in "UX_STL_Ext.h".
//-------------------------------------------------------------------

#ifndef _UXS_JAVA_TYPE_INFO_H
#define _UXS_JAVA_TYPE_INFO_H

#pragma once

#include "JavaEnvironment.h"

namespace UX_STL
{
namespace  Java
{
	
	//
	// Java Type Code
	//

	template <typename T>	struct JniTypeName {};

#	define TYPE_CODE( _type, _code ) \
		template <> \
		struct JniTypeName< _type >	\
		{ \
			typedef _type	type; \
			\
			static void Add (INOUT string &s)  { s << _code; } \
		}

	TYPE_CODE( void,			'V' );
	TYPE_CODE( jboolean,		'Z' );
	TYPE_CODE( jbyte,			'B' );
	TYPE_CODE( jchar,			'C' );
	TYPE_CODE( jshort,			'S' );
	TYPE_CODE( jint,			'I' );
	TYPE_CODE( jlong,			'J' );
	TYPE_CODE( jfloat,			'F' );
	TYPE_CODE( jdouble,			'D' );
	TYPE_CODE( jstring,			"Ljava/lang/String;" );
	TYPE_CODE( jobject,			"Ljava/lang/Object;" );
	TYPE_CODE( jthrowable,		"Ljava/lang/Throwable;" );
		
	TYPE_CODE( jbyteArray,		"[B" );
	TYPE_CODE( jcharArray,		"[C" );
	TYPE_CODE( jshortArray,		"[S" );
	TYPE_CODE( jintArray,		"[I" );
	TYPE_CODE( jlongArray,		"[J" );
	TYPE_CODE( jfloatArray,		"[F" );
	TYPE_CODE( jdoubleArray,	"[D" );

#	undef TYPE_CODE


	template <typename T>
	struct JniTypeName< T *>
	{
		typedef T *		type;

		static void Add (INOUT string &s)  { s << '['; JniTypeName<T>::Add( s ); }
	};


#	define UX_DECL_JAVA_TYPE( _name, _java_name ) \
		\
		namespace UX_STL { \
		namespace Java { \
			struct _name { \
				typedef jobject	type; \
				\
				type	obj; \
				\
				_name () : obj(null) {} \
				_name (const _name &other) : obj(other.obj) {} \
				_name (type obj) : obj(obj) {} \
				\
				operator type () const	{ return obj; } \
			}; \
			\
			template <> \
			struct JniTypeName< _name >	\
			{ \
				typedef _name::type	type; \
				\
				static void Add (INOUT string &s)	{ s << 'L' << _java_name << ';'; } \
			}; \
		}}

	
}	// Java
}	// UX_STL

#endif	// _UXS_JAVA_TYPE_INFO_H